<form method="post">
  商户号：<input type="text" name="partnerId" value="<?= isset($_POST['partnerId']) ? $_POST['partnerId'] : '' ?>"><br/>
  商户密钥：<input type="text" name="secretKey" value="<?= isset($_POST['secretKey']) ? $_POST['secretKey'] : '' ?>"><br/>
  商户订单号：<input type="text" name="orderNo" value="<?= isset($_POST['orderNo']) ? $_POST['orderNo'] : '' ?>"><br/>
  状态： <select name="status">
          <option value="">请选择你要测试的订单状态</option>
          <option value="success">支付成功</option>
          <option value="fail">支付失败</option>
          <option value="authorizing">预授权待确认</option>
          <option value="authorizingTrue">预授权撤销</option>
          <option value="authorizingFail">预授权确认</option>
        </select><br/>
  通知地址：<input type="text" name="url" value="<?= isset($_POST['url']) ? $_POST['url'] : ''  ?>"><br/>
        <button type="submit">提交</button>
</form>

<?php

$args = filter_input_array(INPUT_POST);

file_put_contents('./test.log',json_encode($args)."\n\n",FILE_APPEND);

if(!empty($args)){
  $partnerId = $args['partnerId'];
  $secretKey = $args['secretKey'];
  $merchOrderNo = $args['orderNo'];
  $status = $args['status'];
  $notifyUrl = $args['url'];

  $o = date('YmdHis').mt_rand(100000,999999);

  $datas = [
    'orderNo'=>$o,
    'notifyTime'=>date('Y-m-d H:i:s'),
    'resultCode'=>'EXECUTE_SUCCESS',
    'description'=>'success',
    'resultMessage'=>'成功',
    'version'=>'1.0',
    'protocol'=>'httpPost',
    'service'=>'cardAcquiringCashierPay',
    'success'=>'true',
    'signType'=>'MD5',
    'merchOrderNo'=>$merchOrderNo,
    'partnerId'=>$partnerId,
    'status'=>$status
  ];

  ksort($datas);

  $waitStr = '';

  foreach ($datas as $key => $value) {
    $waitStr .= $key.'='.$value.'&';
  }

  $waitStr = trim($waitStr,'&').$secretKey;

  file_put_contents('./test.log',$waitStr."\n\n",FILE_APPEND);

  echo "===============待签字符串==================<br>";

  echo $waitStr;

  $datas['sign'] = md5($waitStr);

  $ch  = curl_init ();
  $a   = array(" ");
  $b   = array("%20");
  $url = str_replace($a, $b, $notifyUrl);
  @curl_setopt($ch, CURLOPT_URL, $url);
  @curl_setopt($ch,CURLOPT_HEADER,0);
  @curl_setopt($ch,CURLOPT_TIMEOUT,30);
  @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  if(count($datas)>0)
  {
    @curl_setopt($ch, CURLOPT_POST, 1 );
    @curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
  }

  if(strstr($notifyUrl,'https')){
    @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  }

  $data = @curl_exec( $ch );
  curl_close ( $ch );
  echo "<br>===============接收网站返回消息==================<br>";
  var_dump($data);


}
